Homework 1

Charlotte Uden

August 29, 2018

Homework 1:

Interesting fact about myself: My two sisters and I all go by the male versions of our names: Alex, Harri and Charlie

Homework 2:

Typora & Thinking on Paper

This term I will be working with Jane Molofsky from the Plant Biology department. As we have only met once about the project, I only have a novice understanding. Having said that, organising my thoughts on paper and using typora is a good place to start.

What is the big question being asked?

What stage of the Centaura (an invasive plant species) is most vulnerable to biological control?

What are specific hypothese and mechanisms being explored?

The hypothesis here is that biological control will be most evvective when the probability of survival is lowest. SO, what is the probability that the plant will make it to the next stage of its life cycle? The following data is being collected in the field each year:
1. number of individuals that survive to the next stage in the life cycle
2. number of individuals that stay in the same state
3. number of individuals that die
It will be my job to figure out the probability of surviving to the next generation.

How will these results be interpreted?

Low probabilities indicate a vulnerable stage of the Centauea life cycle.

Below is a flow chart I made (using Typora) to get a clearer understanding of how Centaurea progresses through each stage of its life.

I also drew a sketch on paper of how the data may be organised. Here is a picture of it:

Homework #4

1.

x <- 1.1
a <- 2.2
b <- 3.3
#a
z <- x^(a^b)
print(z)
## [1] 3.61714
#b
z <- (x^a)^b
print(z)
## [1] 1.997611
#c
z <- 3*x^3+2*x^2+1
print(z)
## [1] 7.413

2

#a
z <- seq(from=1, to=8, by=1)
z <- rep(x=c(z[1:8],z[7:1]))
print(z)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
#OR
z <- seq(from=1, to=8, by=1)
y <- c(z[7:1])
z <- c(z,y)
print(z)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
#b
z <- seq(from=1, to=5, by=1)
z <- rep(x=z, times=z)
print(z)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
#c
z <- seq(from=1, to=5, by=1)
z <- rep(x=c(z[5:1]), times=c(z[1:5]))
print(z)
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

3

# Polar coordinates can be written as ordered pair, (r,theta). r is distance form pole to point P. Theta is the angle measured from polar axis to line that passes through pole. 

polarCoord <- runif(2) #make a matrix of two random uniform numbers
print(polarCoord)
## [1] 0.08415432 0.76534122
x <- polarCoord[1] #first number in martix is x
y <- polarCoord[2] #second number in matrix is y

r <- sqrt(x^2+y^2)
theta <- atan(x/y)

print(r)
## [1] 0.769954
print(theta)
## [1] 0.1095166

4

queue <- c("sheep", "fox", "owl", "ant")
print(queue)
## [1] "sheep" "fox"   "owl"   "ant"
#a Serpant arrives 
queue <- c(queue,"serpant")
print(queue)
## [1] "sheep"   "fox"     "owl"     "ant"     "serpant"
#b Sheep enters the ark
queue <- c(queue[2:5])
print(queue)
## [1] "fox"     "owl"     "ant"     "serpant"
#c Donkey talks his way to the front
#queue[1] <- "donkey" this replaces the first column with donkey
queue <- c("donkey",queue) 
print(queue)
## [1] "donkey"  "fox"     "owl"     "ant"     "serpant"
#d The serpant leaves
queue <- queue[-5]
print(queue)
## [1] "donkey" "fox"    "owl"    "ant"
#e The owl gets bored and leaves
queue <- queue[-3]
print(queue)
## [1] "donkey" "fox"    "ant"
#f Ant lets aphid cut the line
queue <- c(queue[1:2],"aphid",queue[3])
print(queue)
## [1] "donkey" "fox"    "aphid"  "ant"
#g In what postition is the aphid?

#match(c("aphid",queue))

#regexpr("aphid",queue)

#ind("aphid",queue)

5

# Use r to create a vector of all integers from 1 to 100 not divisible by 2,3 or 7.

z <- c(1:100)
z
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
##  [18]  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34
##  [35]  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51
##  [52]  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68
##  [69]  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85
##  [86]  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100
# which(!z%/%2==0) gives you and index of elements in Z not (!) divisible (%%) by 2. 
# z[which(!z%/%2==0)] gives you the values in the index. so,
a <- z[which(!z%/%2==0)]
b <- z[which(!z%/%3==0)]
c <- z[which(!z%/%7==0)]

# Use the & operator to combine all logical operations:

d <- z[which(!z%%2==0 & !z%%3==0 & !z%%7==0)]

print(d)
##  [1]  1  5 11 13 17 19 23 25 29 31 37 41 43 47 53 55 59 61 65 67 71 73 79
## [24] 83 85 89 95 97

6

Find:()

Replace: ,

7

Find: (+)()()(+)()()(..*)(|)

Broke each line into 6 elements: 1. a word more than one character long 2. not a character (the comma) 3. space 4. word 5. not character (comma) 6. space 7. rest of the line 8. space OR (|) line break

Replace: ()

8

Find: (+)()(((+)()(+))|((+)()(+)()(+)()(+)))()(+)() (+)()(((+)()(+))|((+)()(+)()(+)()(+)))()(+)()()

Replace:

9

Homework #5

#1 
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
data(iris)
glimpse(iris)
## Observations: 150
## Variables: 5
## $ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9,...
## $ Sepal.Width  <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1,...
## $ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5,...
## $ Petal.Width  <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1,...
## $ Species      <fct> setosa, setosa, setosa, setosa, setosa, setosa, s...
# There are 5 variables and 150 observations in this data set. 

#2

iris1 <- filter(iris, Species %in% c("virginica","versicolor"), Sepal.Length > 6, Sepal.Width > 2.5)
glimpse(iris1)
## Observations: 56
## Variables: 5
## $ Sepal.Length <dbl> 7.0, 6.4, 6.9, 6.5, 6.3, 6.6, 6.1, 6.7, 6.1, 6.1,...
## $ Sepal.Width  <dbl> 3.2, 3.2, 3.1, 2.8, 3.3, 2.9, 2.9, 3.1, 2.8, 2.8,...
## $ Petal.Length <dbl> 4.7, 4.5, 4.9, 4.6, 4.7, 4.6, 4.7, 4.4, 4.0, 4.7,...
## $ Petal.Width  <dbl> 1.4, 1.5, 1.5, 1.5, 1.6, 1.3, 1.4, 1.4, 1.3, 1.2,...
## $ Species      <fct> versicolor, versicolor, versicolor, versicolor, v...
# there are 17 observations and 5 variables

#3 

iris2 <- select(iris1, Species, Sepal.Length, Sepal.Width)
glimpse(iris2)
## Observations: 56
## Variables: 3
## $ Species      <fct> versicolor, versicolor, versicolor, versicolor, v...
## $ Sepal.Length <dbl> 7.0, 6.4, 6.9, 6.5, 6.3, 6.6, 6.1, 6.7, 6.1, 6.1,...
## $ Sepal.Width  <dbl> 3.2, 3.2, 3.1, 2.8, 3.3, 2.9, 2.9, 3.1, 2.8, 2.8,...
# there are 17 observations and 3 variables. 

#4 

iris3 <- arrange(iris2, desc(Sepal.Length))
head(iris3)
##     Species Sepal.Length Sepal.Width
## 1 virginica          7.9         3.8
## 2 virginica          7.7         3.8
## 3 virginica          7.7         2.6
## 4 virginica          7.7         2.8
## 5 virginica          7.7         3.0
## 6 virginica          7.6         3.0
#5 

iris4 <- mutate(iris3, Sepal.Area=Sepal.Length*Sepal.Width)
glimpse(iris4)
## Observations: 56
## Variables: 4
## $ Species      <fct> virginica, virginica, virginica, virginica, virgi...
## $ Sepal.Length <dbl> 7.9, 7.7, 7.7, 7.7, 7.7, 7.6, 7.4, 7.3, 7.2, 7.2,...
## $ Sepal.Width  <dbl> 3.8, 3.8, 2.6, 2.8, 3.0, 3.0, 2.8, 2.9, 3.6, 3.2,...
## $ Sepal.Area   <dbl> 30.02, 29.26, 20.02, 21.56, 23.10, 22.80, 20.72, ...
# there are 17 observations and 4 variables

#6 

iris5 <- summarize(iris4, mean(Sepal.Length), mean(Sepal.Width), number=n())
print(iris5)
##   mean(Sepal.Length) mean(Sepal.Width) number
## 1           6.698214          3.041071     56
#7 

iris6 <- group_by(iris4, Species)
iris6 <- summarize(iris6, mean(Sepal.Length), mean(Sepal.Width), number=n())
print(iris6)
## # A tibble: 2 x 4
##   Species    `mean(Sepal.Length)` `mean(Sepal.Width)` number
##   <fct>                     <dbl>               <dbl>  <int>
## 1 versicolor                 6.48                2.99     17
## 2 virginica                  6.79                3.06     39
#8

iris %>%
  filter(Species %in% c("virginica","versicolor"), Sepal.Length > 6, Sepal.Width > 2.5) %>%
  select(Species, Sepal.Length, Sepal.Width) %>%
  arrange(desc(Sepal.Length)) %>%
  mutate(Sepal.Area=Sepal.Length*Sepal.Width) %>%
  group_by(Species)%>%
  summarize(mean(Sepal.Length), mean(Sepal.Width), number=n())
## # A tibble: 2 x 4
##   Species    `mean(Sepal.Length)` `mean(Sepal.Width)` number
##   <fct>                     <dbl>               <dbl>  <int>
## 1 versicolor                 6.48                2.99     17
## 2 virginica                  6.79                3.06     39